﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Procenge.PortalVendas.Models;

namespace Procenge.PortalVendas.Models
{
    public class ModelCompra
    {
        private MORDataContext contexto;

        public ModelCompra()
        {

            contexto = new MORDataContext();
        }

        public IQueryable<Compra> ListarCompra()
        {

            var lista = from comp in contexto.Compras
                        select comp;
            return lista;

        }

        public void CriarCompra(Compra compra)
        {
            contexto.Compras.InsertOnSubmit(compra);

           Salvar();
        }

        public void RemoverCompra(int nf)
        {

            Compra compra = BuscarCompraNf(nf);
            contexto.Compras.DeleteOnSubmit(compra);
            Salvar();




        }

        public Compra BuscarCompraNf(int nf)
        {
            Compra compra = contexto.Compras.Single(a => a.notaFiscal == nf);
            return compra;

        }

        public void Salvar()
        {
            contexto.SubmitChanges();
        }
    }
}